package com.tongji.housediy.view
{
	import com.tongji.housediy.events.GetHouseByIDEvent;
	import com.tongji.housediy.model.ExchangeDataModel;
	import com.tongji.housediy.model.HouseModel;
	import com.tongji.housediy.model.ViewControlModel;
	import com.tongji.housediy.view.titlewindows.EntryTitleWindow;
	
	import flash.events.MouseEvent;
	import flash.external.ExternalInterface;
	
	import mx.binding.utils.BindingUtils;
	import mx.controls.Alert;
	import mx.managers.PopUpManager;
	
	import org.robotlegs.mvcs.Mediator;
	
	/**
	 * 
	 * @author chenchao
	 * 
	 */
	public class DesignContentMediator extends Mediator
	{
		[Inject]
		public var view:DesignContentComp;
		
		[Inject]
		public var viewControlModel:ViewControlModel;
		[Inject]
		public var houseModel:HouseModel;
		
		[Inject]
		public var roomModel:ExchangeDataModel;
		
		override public function onRegister():void
		{
			BindingUtils.bindProperty(view, "selectedIndex", viewControlModel, "dimensionIndex");
			
			var param:String = ExternalInterface.call("window.location.search.substring", 1); 
			
			var params:Object  = {};
			var pos:int = param.indexOf("="); 
			if(pos != -1) { 
				var argname:String = param.substring(0, pos); 
				var value:String =param.substring(pos+1); 
				
				params[argname] = value; 
				houseModel.houseID = int(value);
			} 

			if (houseModel.houseID != 0)
			{
				dispatch(new GetHouseByIDEvent(GetHouseByIDEvent.GET_HOUSE_BY_ID, houseModel.houseID));
			}
			else
			{
				var entryWindow:EntryTitleWindow = new EntryTitleWindow();
				PopUpManager.addPopUp(entryWindow, view.parent, true);
				PopUpManager.centerPopUp(entryWindow); 
				mediatorMap.createMediator(entryWindow);
			}
		}
		

	}
}